const observe = function (obj) {
    console.log('-2',)
    // 给传入对象的每一个属性（包括原型链上的）作响应式处理
    for (const key in obj) {
        console.log('-3')
        let innerValue = obj[key]       //一直存在，闭包的应用
        const Dep = new Set()
        console.log('-4')
        Object.defineProperty(obj, key, {
            get: function () {
                // console.log('-1', window.__myFn)
                console.log('-1')
                Dep.add(window.__myFn)  //这个依赖存进去
                console.log('000')
                return innerValue
            },
            set: function (val) {
                innerValue = val
                // 遍历每一个依赖，执行
                for (const fn of Dep) {
                    debounce(fn, 800)()  //防抖修改dom
                }
            }
        })
    }
}

function autoRun(fn) {
    console.log('222')
    window.__myFn = fn  //1.先在window上挂载依赖
    window.__myFn()     //得到姓、名（执行了get）
    window.__myFn = null
}

function debounce(fn, wait = 0) {
    let time
    return function (...args) {
        const that = this
        clearTimeout(time)
        time = setTimeout(() => {
            fn.apply(that, args)
        }, wait)
    }
}